package com.example.lots_of_demo.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.lots_of_demo.dao.MenuDao;
import com.example.lots_of_demo.model.Menu;
import com.example.lots_of_demo.model.REnum;
import com.example.lots_of_demo.security.SecurityUser;
import com.example.lots_of_demo.service.MenuService;
import com.example.lots_of_demo.utils.MenuUtils;
import com.example.lots_of_demo.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author : LZJ
 * @description : code for LZJ
 * @date : 2021/2/14
 */
@Service
public class MenuServiceImpl extends ServiceImpl<MenuDao, Menu> implements MenuService {

    @Autowired
    private MenuDao menuDao;

    @Override
    public R getMenu() {
        SecurityUser securityUser = (SecurityUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        List<Menu> menus = menuDao.getMenu(securityUser.getUsername());
        return R.createSuccess(REnum.RSuccessResponse.SELECT_SUCCESS_RESPONSE, MenuUtils.transferMenuVo(menus));
    }

}
